package me.ree.zkproduct.controller;

import me.ree.zkproduct.annotation.MyCustomAnnotation;
import me.ree.zkproduct.handler.ApplicationContextHandler;
import me.ree.zkproduct.service.impl.ServiceA;
import me.ree.zkproduct.service.impl.ServiceB;
import me.ree.zkproduct.util.JsonUtil;
import me.ree.zkproduct.util.Resp;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
//@MyCustomAnnotation
public class TestController {

    /**
     * 验证@Lazy是否能解决循环依赖
     * @return
     */
    @PostMapping("/cyclic")
    @MyCustomAnnotation
    public Resp<Boolean> testCyclicDependenceByLazy() {
        ServiceA serviceA = ApplicationContextHandler.getBean("serviceA");
        ServiceB serviceB = ApplicationContextHandler.getBean("serviceB");
////        Assert.isTrue(serviceB1 == serviceB, "serviceB1 != serviceB");
//        ServiceA serviceA1 = serviceB.getServiceA();
////        Assert.isTrue(serviceA1 == serviceA, "serviceA1 != serviceA");
//
//        ServiceB serviceB1 = serviceA.getServiceB();
//        ServiceB serviceB2 = serviceA1.getServiceB();

        serviceA.setName("serviceA");
        serviceA.setAge(10);

        serviceB.setName("serviceB");
        serviceB.setAge(5);

//        System.out.println(JsonUtil.toJson(Resp.ok(serviceA)));

        return Resp.ok(true);
    }
}
